// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.radio.script;

import java.util.ArrayList;
import java.util.List;
import zombie.core.Rand;
import zombie.debug.DebugLog;
import zombie.debug.DebugType;
import zombie.radio.globals.CompareResult;

public final class ExitOptionOld {
    private String parentScript;
    private String name;
    private ConditionContainer condition;
    private List<RadioScriptEntry> scriptEntries = new ArrayList();

    public ExitOptionOld(String parentName, String _name) {
        this.parentScript = parentName != null ? parentName : "Noname";
        this.name = _name != null ? _name : "Noname";
    }

    public void setCondition(ConditionContainer conditionContainer) {
        this.condition = conditionContainer;
    }

    public void addScriptEntry(RadioScriptEntry entry) {
        if (entry != null) {
            this.scriptEntries.add(entry);
        } else {
            DebugLog.log(DebugType.Radio, "Error trying to add 'null' scriptentry in script: " + this.parentScript + ", exitoption: " + this.name);
        }
    }

    public RadioScriptEntry evaluate() {
        CompareResult compareResult = CompareResult.True;
        if (this.condition != null) {
            compareResult = this.condition.Evaluate();
        }

        if (compareResult.equals(CompareResult.True)) {
            if (this.scriptEntries != null && this.scriptEntries.size() > 0) {
                int _int = Rand.Next(100);

                for (RadioScriptEntry radioScriptEntry : this.scriptEntries) {
                    if (radioScriptEntry != null) {
                        System.out.println("ScriptEntry " + radioScriptEntry.getScriptName());
                        System.out.println("Chance: " + _int + " Min: " + radioScriptEntry.getChanceMin() + " Max: " + radioScriptEntry.getChanceMax());
                        if (_int >= radioScriptEntry.getChanceMin() && _int < radioScriptEntry.getChanceMax()) {
                            return radioScriptEntry;
                        }
                    }
                }
            }
        } else if (compareResult.equals(CompareResult.Invalid)) {
            System.out.println("Error occured evaluating condition: " + this.parentScript + ", exitoption: " + this.name);
            DebugLog.log(DebugType.Radio, "Error occured evaluating condition: " + this.parentScript + ", exitoption: " + this.name);
        }

        return null;
    }
}
